function main(pageId, param) {
    return new Promise((resolve, reject) => {
        debugger
        console.log(pageId, param);
        let result = window.selectMatter || [];
        let dataListJson = transformSelectMatter(result)
        resolve(dataListJson);
    })
}


function transformSelectMatter(selectMatterArray) {
    // Convert empty/null to empty array to prevent errors
    const safeArray = Array.isArray(selectMatterArray) ? selectMatterArray : [];

    return {
        hasError: false,
        result: safeArray.map(item => ({
            version: null,
            data: transformItem(item)
        })),
        message: null,
        tag: null,
        totalCount: safeArray.length.toString()
    };
}

function transformItem(item) {
    if (!item || typeof item !== 'object') {
        return {};
    }

    return Object.keys(item).reduce((acc, key) => {
        acc[key] = {
            icon: null,
            style: null,
            value: item[key] !== undefined && item[key] !== null ? item[key] : ''
        };
        return acc;
    }, {});
}
